/**
 * LEKU APPLIANCE CHAINS.
 * Copyright (c) 2016-2016 All Rights Reserved.
 */
package com.leku.mse.mq.listener.diary;

import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.fastjson.JSON;
import com.leku.mse.entity.diary.DiaryOptEntity;
import com.leku.mse.service.diary.DiaryService;

/**
 * 功能描述: 手账删除监听
 *
 * @author suiying
 * @created 2018年1月2日
 * @version 1.0.0
 */
public class DiaryDelListener implements MessageListener {

    private static final Logger LOG = LoggerFactory.getLogger(DiaryDelListener.class);

    @Autowired
    private DiaryService diaryService;

    /*
     * (non-Javadoc)
     * @see javax.jms.MessageListener#onMessage(javax.jms.Message)
     */
    @Override
    public void onMessage(Message message) {
        String msg = null;

        try {
            TextMessage textMsg = (TextMessage) message;

            msg = textMsg.getText();

            diaryService.dealRemoveDiary(JSON.parseObject(msg, DiaryOptEntity.class));
        } catch (Exception e) {
            LOG.error("手账删除队列消息异常,消息为：" + msg, e);
        }

        LOG.info("手账删除队列消息:" + msg);
    }

}
